package com.cqjtu.graduation.entity;

import com.cqjtu.graduation.util.StringToDate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;

public class OrderDO extends BaseDO {
    private Integer orderId; //订单号
    private DinnerTableDO dinnerTableDO;
    private UserDO userDO;//用来表示订单与用户的外键关系
    private Float orderTotalPrice;  //订单总价
    private Date orderMealTime; //  点餐时间
    private Date orderSettleAccountsTime;//订单结算时间
    private String orderState;   //订单状态
    private List<FoodTypeListDO> foodTypeListDO;

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public DinnerTableDO getDinnerTableDO() {
        return dinnerTableDO;
    }

    public void setDinnerTableDO(DinnerTableDO dinnerTableDO) {
        this.dinnerTableDO = dinnerTableDO;
    }
    public UserDO getUserDO() {
        return userDO;
    }

    public void setUserDO(UserDO userDO) {
        this.userDO = userDO;
    }

    public Float getOrderTotalPrice() {
        return orderTotalPrice;
    }

    public void setOrderTotalPrice(Float orderTotalPrice) {
        this.orderTotalPrice = orderTotalPrice;
    }

    public String getOrderMealTime() {
        return StringToDate.dateToString(orderMealTime);
    }

    public void setOrderMealTime(String orderMealTime) {
        SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            this.orderMealTime = format.parse(orderMealTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    public String getOrderSettleAccountsTime() {
        return  StringToDate.dateToString(orderSettleAccountsTime);
    }

    public void setOrderSettleAccountsTime(String orderSettleAccountsTime) {
        SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            this.orderSettleAccountsTime = format.parse(orderSettleAccountsTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    public String getOrderState() {
        return orderState;
    }

    public void setOrderState(String orderState) {
        this.orderState = orderState;
    }

    public List<FoodTypeListDO> getFoodTypeListDO() {
        return foodTypeListDO;
    }

    public void setFoodTypeListDO(List<FoodTypeListDO> foodTypeListDO) {
        this.foodTypeListDO = foodTypeListDO;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof OrderDO)) return false;
        OrderDO orderDO = (OrderDO) o;
        return getOrderId().equals(orderDO.getOrderId()) &&
                getDinnerTableDO().equals(orderDO.getDinnerTableDO()) &&
                getUserDO().equals(orderDO.getUserDO()) &&
                getOrderTotalPrice().equals(orderDO.getOrderTotalPrice()) &&
                getOrderMealTime().equals(orderDO.getOrderMealTime()) &&
                getOrderSettleAccountsTime().equals(orderDO.getOrderSettleAccountsTime()) &&
                getOrderState().equals(orderDO.getOrderState()) &&
                getFoodTypeListDO().equals(orderDO.getFoodTypeListDO());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getOrderId(), getDinnerTableDO(), getUserDO(), getOrderTotalPrice(), getOrderMealTime(), getOrderSettleAccountsTime(), getOrderState(), getFoodTypeListDO());
    }

    @Override
    public String toString() {
        return "OrderDO{" +
                "orderId=" + orderId +
                ", dinnerTableDO=" + dinnerTableDO +
                ", userDO=" + userDO +
                ", orderTotalPrice=" + orderTotalPrice +
                ", orderMealTime=" + orderMealTime +
                ", orderSettleAccountsTime=" + orderSettleAccountsTime +
                ", orderState='" + orderState + '\'' +
                ", foodTypeListDO=" + foodTypeListDO +
                '}';
    }
}
